xen/hypfs: check the return value of snprintf to avoid leaking stack accidently
authorXenia Ragiadakou <burzalodowa@gmail.com>
Fri, 5 Aug 2022 06:38:23 +0000 (08:38 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 5 Aug 2022 06:38:23 +0000 (08:38 +0200)
commit33bd9c91865b420adec02380c465e81031b0150a
tree0102c922aefaccfffc78ecf03a73684575d6feda
parent7177b2c3265a18722cd4a89542a28815f7b13622
xen/hypfs: check the return value of snprintf to avoid leaking stack accidently

The function snprintf() returns the number of characters that would have been
written in the buffer if the buffer size had been sufficiently large,
not counting the terminating null character.
Hence, the value returned is not guaranteed to be smaller than the buffer size.
Check the return value of snprintf() to prevent leaking stack contents to the
guest by accident.

Also, for debug builds, add an assertion to ensure that the assumption made on
the size of the destination buffer still holds.

Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
xen/common/hypfs.c